package com.bridgeintelligent.tag.engine.mvc;

import com.alibaba.fastjson.JSONArray;
import com.bridgeintelligent.tag.engine.api.*;
import com.bridgeintelligent.tag.engine.api.looklike.LookLikeQueryModel;
import com.bridgeintelligent.tag.engine.api.looklike.LookLikeResult;
import com.bridgeintelligent.tag.engine.api.rsp.*;
import com.bridgeintelligent.tag.engine.api.rsp.DimAnalysisRsp.R;
import com.bridgeintelligent.tag.engine.api.theme.ThemeDetailResult;
import com.bridgeintelligent.tag.engine.api.theme.ThemeQueryModel;
import com.bridgeintelligent.tag.engine.core.cache.CacheConfig;
import com.bridgeintelligent.tag.engine.core.cache.CacheUtils;
import com.bridgeintelligent.tag.engine.es.model.AnalysisAggregationModel;
import com.bridgeintelligent.tag.engine.es.model.CustomerDetailModel;
import com.bridgeintelligent.tag.engine.es.model.CustomersAnalysisModel;
import com.bridgeintelligent.tag.engine.es.model.DimAggregationModel;
import com.bridgeintelligent.tag.engine.mvc.service.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wayneleo.quickstart.framework.ExceptionCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by JackCheung on 2019/9/24 4:59 PM.
 */
@Api(tags = "引擎查询模块")
@AllArgsConstructor
@RestController
@Slf4j
@RequestMapping(value = "/api/engine")
public class EngineQueryController {

    private IEngineQueryService iEngineQueryService;
    private ObjectMapper objectMapper;
    final private ICustomersAnalysisService customersAnalysisService;

    final private IDimAggregationService dimAggregationService;

    private ICustomerDetailService customerDetailService;

    private ICustQueryService custQueryService;

    private IAnalysisAggregationService analysisAggregationService;

    private IMultiAnalysisAggregationService multiAnalysisAggregationService;

    private ILookLikeAggreagtionService lookLikeAggreagtionService;

    private IThemeDetailService themeDetailService;

    @ApiOperation(value = "数据集查询", notes = "引擎查询模块")
    @PostMapping("/dataSet")
    public DataSetRsp dataSet(String config) {
        DataSetRsp result = null;
        try {
            //将查询json转为QueryModel对象
            QueryModel queryModel = objectMapper.readValue(config, QueryModel.class);
            //查询结果
            result = iEngineQueryService.dataSet(queryModel);
        } catch (Exception e) {
            log.info("数据集查询异常",e);
        }
        return result;
    }

    @ApiOperation(value = "聚合分析", notes = "引擎查询模块")
    @PostMapping("/index")
    public IndexRsp index(String config) throws IOException {
        //把json转为IndexQueryModel对象
        IndexModel indexQueryModel = objectMapper.readValue(config, IndexModel.class);
        //查询分析结果
        return iEngineQueryService.index(indexQueryModel);
    }

    @ApiOperation(value = "客群分析", notes = "引擎查询模块")
    @PostMapping("/customerGroup")
    public CustomerGroupRsp customerGroup(String config) {
        CustomerGroupRsp result = null;
        try {
            //将查询json转为QueryModel对象
            QueryModel queryModel = objectMapper.readValue(config, QueryModel.class);
            //查询结果
            result = iEngineQueryService.customerGroup(queryModel);
        } catch (Exception e) {
            log.info("客群分析异常",e);
        }
        return result;
    }

    @ApiOperation(value = "微观画像", notes = "引擎查询模块")
    @PostMapping("/microPortrait")
    public MicroPortraitRsp microPortrait(String filterName, String filterValue) {
        return iEngineQueryService.microPortrait(filterName, filterValue);
    }

    @ApiOperation(value = "客群洞察-单个标签", notes = "引擎查询模块")
    @PostMapping("/customersAnalysis")
    public DimAnalysisRsp customersAnalysis(String condition) {
        try {
            CustomersAnalysisModel queryModel = objectMapper.readValue(condition, CustomersAnalysisModel.class);
            if(StringUtils.isBlank(queryModel.getField())){
                throw new EngineException(new ExceptionCode(400,"参数错误"));
            }
            return DimAnalysisRsp.of().setData(customersAnalysisService.getSingleFieldValue(queryModel));
        } catch (IOException e) {
            log.error("客群洞察失败",e);
            return DimAnalysisRsp.of().setData(R.of());
        }
    }

    @ApiOperation(value = "客群洞察-多个标签", notes = "引擎查询模块")
    @PostMapping("/customersMultiAnalysis")
    public MultiDimAnalysisRsp customersMultiAnalysis(String condition) {
        log.info("接收参数："+condition);
        try {
            CustomersAnalysisModel queryModel = objectMapper.readValue(condition, CustomersAnalysisModel.class);
            if(CollectionUtils.isEmpty(queryModel.getFields())){
                throw new EngineException(new ExceptionCode(400,"参数错误"));
            }
            return MultiDimAnalysisRsp.of().setData(customersAnalysisService.getFieldValues(queryModel));
        } catch (Exception e) {
            log.error("客群洞察失败",e);
            return MultiDimAnalysisRsp.of().setData(Collections.emptyList());
        }
    }

    @ApiOperation(value = "客户信息查询", notes = "引擎查询模块")
    @PostMapping("/customerDetail")
    public CustomerDetailRsp customerDetail(String condition) {
        try {
            CustomerDetailModel queryModel = objectMapper.readValue(condition, CustomerDetailModel.class);
            if(StringUtils.isEmpty(queryModel.getQueryKey()) || (queryModel.getQueryKey().length() != 10 && queryModel.getQueryKey().length() != 19)){
                return new CustomerDetailRsp().setCode(-1).setMessage("参数错误");
            }
            return new CustomerDetailRsp().setCode(0).setData(customerDetailService.customerDetail(queryModel));
        } catch (Exception e) {
            log.error("客户信息查询失败",e);
            return new CustomerDetailRsp().setCode(-1).setMessage("客户信息查询失败");
        }
    }

    @ApiOperation(value = "客群洞察-根据某个标签动态二次聚合", notes = "引擎查询模块")
    @PostMapping("/customersDimAggregation")
    public DimAggregationRsp customersDimAggregation(String condition) {
        try {
            DimAggregationModel queryModel = objectMapper.readValue(condition, DimAggregationModel.class);
            DimAggregationRsp resp = dimAggregationService.getFieldAggregation(queryModel);
            resp.setFields(queryModel.getFields());
            resp.setAggMap(queryModel.getAggMap());
            return resp;
        } catch (IOException e) {
            log.error("客群洞察-二次聚合失败",e);
            return DimAggregationRsp.of().setData(Collections.emptyList());
        }
    }


    @ApiOperation(value = "根据客群输出客户号", notes = "引擎查询模块")
    @PostMapping("/custQuery")
    public CustQuerySetRsp custQuery(String config) {
        CustQuerySetRsp result = new CustQuerySetRsp();;
        try {
            //将查询json转为QueryModel对象
            CustQueryModel queryModel = objectMapper.readValue(config, CustQueryModel.class);
            //查询结果
            result = custQueryService.custQuery(queryModel);
        } catch (Exception e) {
            log.error("********根据客群输出客户号功能失败",e);
            result.setCode(-1);
            result.setMsg("查询失败"+e.getMessage());
            CustQuerySetRsp.DataRsp dataRsp = new CustQuerySetRsp.DataRsp();
            result.setData(dataRsp);
        }
        return result;
    }



    @ApiOperation(value = "画像探索-报表展示", notes = "引擎查询模块")
    @PostMapping("/analysisAggregation")
    public AnalysisAggregationRsp analysisAggregation(String condition) {
        /* if (condition.equals("1")){
            condition = "[{\"field\":\"pb_accfund_organname\",\"fields\":[\"age\"],\"filterGroup\":{\"symbol\":\"and\",\"filters\":[{\"dimName\":\"年龄\",\"dimId\":\"age\",\"valueList\":[],\"type\":\"term\",\"id\":\"\",\"classify\":\"03\",\"dataDate\":\"0\",\"timeType\":false,\"staticVal\":\"0\",\"dataName\":\"当前时间\",\"yearValue\":\"2022\",\"dynamicValue\":\"\",\"timeTitle\":false,\"colName\":\"age\"}],\"children\":[],\"location\":\"0\"},\"dataDate\":\"20220515\",\"type\":1}]";
        }else if (condition.equals("2")){
            condition = "[{\"field\":\"age\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"age\",\"type\":2,\"yitems\":[{\"low\":\"-∞\",\"high\":\"30\"},{\"low\":\"30\",\"high\":\"+∞\"}]}]";
        }else if (condition.equals("3")){
            condition = "[{\"field\":\"age\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"age\",\"type\":2,\"items\":[{\"low\":\"-∞\",\"high\":\"30\"},{\"low\":\"30\",\"high\":\"+∞\"}]}]";
        }else if (condition.equals("4")){
            condition = "[{\"field\":\"age\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"age\",\"type\":2,\"items\":[{\"low\":\"-∞\",\"high\":\"30\"},{\"low\":\"30\",\"high\":\"+∞\"}],\"yitems\":[{\"low\":\"0\",\"high\":\"25\"},{\"low\":\"25\",\"high\":\"50\"}]}]";
        }

        else if (condition.equals("5")){
            condition = "[{\"field\":\"age\",\"fields\":[\"age\"],\"dataDate\":\"202212\",\"indexId\":\"1\",\"type\":1}]";
        }else if (condition.equals("6")){
            condition = "[{\"field\":\"age\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"open_acct_dt\",\"type\":2,\"yitems\":[{\"low\":\"-∞\",\"high\":\"20211231\"},{\"low\":\"20211231\",\"high\":\"+∞\"}]}]";
        }else if (condition.equals("7")){
            condition = "[{\"field\":\"age\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"open_acct_dt\",\"type\":2,\"items\":[{\"low\":\"-∞\",\"high\":\"30\"},{\"low\":\"30\",\"high\":\"+∞\"}]}]";
        }else if (condition.equals("8")){
            condition = "[{\"field\":\"age\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"open_acct_dt\",\"type\":2,\"items\":[{\"low\":\"-∞\",\"high\":\"30\"},{\"low\":\"30\",\"high\":\"+∞\"}],\"yitems\":[{\"low\":\"-∞\",\"high\":\"20211231\"},{\"low\":\"20211231\",\"high\":\"+∞\"}]}]";
        }

        else if (condition.equals("9")){
            condition = "[{\"field\":\"age\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"gender_cd\",\"type\":2}]";
        }else if (condition.equals("10")){
            condition = "[{\"field\":\"age\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"gender_cd\",\"type\":2,\"items\":[{\"low\":\"-∞\",\"high\":\"30\"},{\"low\":\"30\",\"high\":\"+∞\"}]}]";
        }

        else if (condition.equals("11")){
            condition = "[{\"field\":\"open_acct_dt\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"age\",\"type\":2}]";
        }else if (condition.equals("12")){
            condition = "[{\"field\":\"open_acct_dt\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"age\",\"type\":2,\"yitems\":[{\"low\":\"-∞\",\"high\":\"30\"},{\"low\":\"30\",\"high\":\"+∞\"}]}]";
        }else if (condition.equals("13")){
            condition = "[{\"field\":\"open_acct_dt\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"age\",\"type\":2,\"items\":[{\"low\":\"-∞\",\"high\":\"20211231\"},{\"low\":\"20211231\",\"high\":\"+∞\"}]}]";
        }else if (condition.equals("14")){
            condition = "[{\"field\":\"open_acct_dt\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"age\",\"type\":2,\"yitems\":[{\"low\":\"-∞\",\"high\":\"30\"},{\"low\":\"30\",\"high\":\"+∞\"}],\"items\":[{\"low\":\"-∞\",\"high\":\"20211231\"},{\"low\":\"20211231\",\"high\":\"+∞\"}]}]";
        }

        else if (condition.equals("15")){
            condition = "[{\"field\":\"open_acct_dt\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"open_acct_dt\",\"type\":2}]";
        }else if (condition.equals("16")){
            condition = "[{\"field\":\"open_acct_dt\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"open_acct_dt\",\"type\":2,\"yitems\":[{\"low\":\"-∞\",\"high\":\"20211231\"},{\"low\":\"20211231\",\"high\":\"+∞\"}]}]";
        }else if (condition.equals("17")){
            condition = "[{\"field\":\"open_acct_dt\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"open_acct_dt\",\"type\":2,\"items\":[{\"low\":\"-∞\",\"high\":\"20211231\"},{\"low\":\"20211231\",\"high\":\"+∞\"}]}]";
        }else if (condition.equals("18")){
            condition = "[{\"field\":\"open_acct_dt\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"open_acct_dt\",\"type\":2,\"yitems\":[{\"low\":\"-∞\",\"high\":\"20211001\"},{\"low\":\"20211001\",\"high\":\"+∞\"}],\"items\":[{\"low\":\"-∞\",\"high\":\"20211231\"},{\"low\":\"20211231\",\"high\":\"+∞\"}]}]";
        }

        else if (condition.equals("19")){
            condition = "[{\"field\":\"open_acct_dt\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"gender_cd\",\"type\":2}]";
        }else if (condition.equals("20")){
            condition = "[{\"field\":\"open_acct_dt\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"gender_cd\",\"type\":2,\"items\":[{\"low\":\"-∞\",\"high\":\"20211231\"},{\"low\":\"20211231\",\"high\":\"+∞\"}]}]";
        }

        else if (condition.equals("21")){
            condition = "[{\"field\":\"gender_cd\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"gender_cd\",\"type\":2}]";
        }

        else if (condition.equals("22")){
            condition = "[{\"field\":\"gender_cd\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"age\",\"type\":2}]";
        }else if (condition.equals("23")){
            condition = "[{\"field\":\"gender_cd\",\"fields\":[\"age\"],\"dataDate\":\"20220515\",\"yfield\":\"age\",\"type\":2,\"yitems\":[{\"low\":\"-∞\",\"high\":\"30\"},{\"low\":\"30\",\"high\":\"+∞\"}]}]";
        }

        else if (condition.equals("24")){
            condition = "[{\"field\":\"gender_cd\",\"fields\":[\"age\"],\"dataDate\":\"20230503\",\"yfield\":\"age\",\"indexId\":\"1\",\"type\":2}]";
        }else if (condition.equals("25")){
            condition = "[{\"field\":\"gender_cd\",\"fields\":[\"age\"],\"dataDate\":\"202212\",\"yfield\":\"age\",\"type\":2,\"indexId\":\"1\"}]";
        }*/
        log.info("画像探索-报表展示-请求参数：{}",condition);
        long t1 = System.currentTimeMillis();
        try {
            List<AnalysisAggregationResult> list = new ArrayList<>();
            List<MultiAnalysisAggregationResult> multiList = new ArrayList<>();
            JSONArray parseArray = JSONArray.parseArray(condition);
            for (int i = 0; i < parseArray.size(); i++) {
                //将查询JSON转为AnalysisAggregationModel对象
                AnalysisAggregationModel model = objectMapper.readValue(parseArray.getString(i), AnalysisAggregationModel.class);
                if (model.getType() == 1){
                    AnalysisAggregationResult analysisAggregation = null;
                    try {
                        analysisAggregation = analysisAggregationService.getAnalysisAggregation(model);
                    }catch (Exception e){
                        log.error("单维聚合分析失败",e);
                        analysisAggregation = defaultOneResult(model);
                    }
                    analysisAggregation.setFields(model.getFieldsFlag());
                    analysisAggregation.setFieldsMap(model.getFieldsMapFlag());
                    list.add(analysisAggregation);
                }
                if (model.getType() == 2){
                    MultiAnalysisAggregationResult multiAnalysisAggregation = null;
                    try {
                        multiAnalysisAggregation = multiAnalysisAggregationService.getMultiAnalysisAggregation(model);
                    }catch (Exception e){
                        log.error("多维聚合分析失败",e);
                        multiAnalysisAggregation = defaultMoreResult(model);
                    }
                    multiAnalysisAggregation.setFields(model.getFieldsFlag());
                    multiAnalysisAggregation.setFieldsMap(model.getFieldsMapFlag());
                    multiList.add(multiAnalysisAggregation);
                }
            }
            long t4 = System.currentTimeMillis();
            log.info("标签聚合总耗时：{}",t4-t1);
            return AnalysisAggregationRsp.of().setCode(0).setMsg("查询成功").setData(list).setAllCount(0l).setTotalCount(0l).setPercent("0%").setMultidata(multiList);
        } catch (Exception e) {
            log.error("画像探索-数据查询失败",e);
            return AnalysisAggregationRsp.of().setCode(-1).setMsg("画像探索失败"+e.getMessage()).setAllCount(0l).setTotalCount(0l).setPercent("0%").setData(new ArrayList<>()).setMultidata(new ArrayList<>());
        }
    }

    private AnalysisAggregationResult defaultOneResult(AnalysisAggregationModel model){
        AnalysisAggregationResult defaultResult = AnalysisAggregationResult.of();
        if (!StringUtils.isEmpty(model.getField())){
            DimInfo dimInfo = CacheUtils.getCacheInfo(CacheConfig.DIM_INFO, model.getField());
            if (null != dimInfo){
                defaultResult.setDimId(dimInfo.getDimId());
                defaultResult.setDimName(dimInfo.getDimName());
                defaultResult.setClassify(dimInfo.getClassify());
            }
        }
        defaultResult.setTotalCount(0l);
        defaultResult.setExistCount(0l);
        defaultResult.setData(new ArrayList<>());
        return defaultResult;
    }

    private MultiAnalysisAggregationResult defaultMoreResult(AnalysisAggregationModel model){

        MultiAnalysisAggregationResult defaultResult = MultiAnalysisAggregationResult.of();
        if (!StringUtils.isEmpty(model.getField())){
            DimInfo xDimInfo = CacheUtils.getCacheInfo(CacheConfig.DIM_INFO, model.getField());
            if (null != xDimInfo){
                defaultResult.setXDimId(xDimInfo.getDimId());
                defaultResult.setXDimName(xDimInfo.getDimName());
                defaultResult.setXClassify(xDimInfo.getClassify());
            }
        }
        if (!StringUtils.isEmpty(model.getYfield())){
            DimInfo yDimInfo = CacheUtils.getCacheInfo(CacheConfig.DIM_INFO, model.getYfield());
            if (null != yDimInfo){
                defaultResult.setYDimId(yDimInfo.getDimId());
                defaultResult.setYDimName(yDimInfo.getDimName());
                defaultResult.setYClassify(yDimInfo.getClassify());
            }
        }
        defaultResult.setTotalCount(0l);
        defaultResult.setData(new ArrayList<>());
        return defaultResult;
    }

    @ApiOperation(value = "画像探索-筛选客群", notes = "引擎查询模块")
    @PostMapping("/analysisCount")
    public AnalysisAggregationRsp analysisCount(String condition) {
        /*if (condition.equals("1")){
            condition = "{\"field\":\"gender_cd\",\"fields\":[\"age\"],\"filterGroup\":{\"symbol\":\"and\",\"filters\":[{\"dimName\":\"性别\",\"dimId\":\"gender_cd\",\"valueList\":[],\"type\":\"term\",\"id\":\"\",\"classify\":\"02\",\"dataDate\":\"0\",\"timeType\":false,\"staticVal\":\"0\",\"dataName\":\"当前时间\",\"yearValue\":\"2022\",\"dynamicValue\":\"\",\"timeTitle\":false,\"colName\":\"gender_cd\"}],\"children\":[],\"location\":\"0\"},\"dataDate\":\"20220515\",\"items\":[{\"low\":\"-∞\",\"high\":\"25\"},{\"low\":\"25\",\"high\":\"+∞\"}]}";
        }*/
        log.info("画像探索-筛选客群-请求参数：{}",condition);
        try {
            AnalysisAggregationModel model = objectMapper.readValue(condition, AnalysisAggregationModel.class);
            return analysisAggregationService.getPercent(model);
        } catch (Exception e) {
            log.error("画像探索-筛选客群失败",e);
            return AnalysisAggregationRsp.of().setCode(-1).setMsg("画像探索-筛选客群失败"+e.getMessage()).setAllCount(0).setTotalCount(0).setPercent("0%");
        }
    }

    @ApiOperation(value = "lookLike分组数据查询", notes = "引擎查询模块")
    @PostMapping("/lookLikeAggeragtion")
    public LookLikeResult lookLikeAggeragtion(String condition) {
        log.info("lookLike分组数据查询-请求参数：{}",condition);
        try {
            LookLikeQueryModel model = objectMapper.readValue(condition, LookLikeQueryModel.class);
            return lookLikeAggreagtionService.lookLikeAnalysis(model);
        } catch (Exception e) {
            log.error("lookLike分组数据查询失败",e);
            return LookLikeResult.of().setCode(-1).setMessage("lookLike分组数据查询失败"+e.getMessage()).setList(new ArrayList<>());
        }
    }

    @ApiOperation(value = "lookLike查询index下的分数最大值最小值", notes = "引擎查询模块")
    @PostMapping("/lookLikeMinMax")
    public LookLikeResult lookLikeMinMax(String condition) {
        log.info("lookLike查询index下的分数最大值最小值-请求参数：{}",condition);
        try {
            LookLikeQueryModel model = objectMapper.readValue(condition, LookLikeQueryModel.class);
            return lookLikeAggreagtionService.findScoreByIndex(model.getEsIndex());
        } catch (Exception e) {
            log.error("lookLike查询index下的分数最大值最小值失败",e);
            return LookLikeResult.of().setCode(-1).setMessage("lookLike查询index下的分数最大值最小值失败"+e.getMessage());
        }
    }


    @ApiOperation(value = "主题明细数据查询", notes = "引擎查询模块")
    @PostMapping("/themeDetail")
    public ThemeDetailResult themeDetail(String condition) {
        ThemeDetailResult result = null;
        try {
            //将查询json转为QueryModel对象
            ThemeQueryModel queryModel = objectMapper.readValue(condition, ThemeQueryModel.class);
            //查询结果
            result = themeDetailService.themeDetailQuery(queryModel);
        } catch (Exception e) {
            log.error("主题明细数据查询",e);
            result = ThemeDetailResult.of().setCode(-1).setMsg("查询出错！");
        }
        return result;
    }


    @ApiOperation(value = "查询某个主题客群的人数", notes = "引擎查询模块")
    @PostMapping("/themeCount")
    public ThemeDetailResult themeCount(String condition) {
        ThemeDetailResult result = null;
        try {
            //将查询json转为QueryModel对象
            ThemeQueryModel queryModel = objectMapper.readValue(condition, ThemeQueryModel.class);
            //查询结果
            int totalCount = themeDetailService.getTotalCount(queryModel);
            result = ThemeDetailResult.of().setCode(0).setTotalCount(totalCount);
        } catch (Exception e) {
            log.error("主题明细数据查询",e);
            result =  ThemeDetailResult.of().setCode(-1).setMsg("查询出错！");
        }
        return result;
    }

    @ApiOperation(value = "查询某个索引下的mapping字段集合", notes = "引擎查询模块")
    @PostMapping("/getIndexMapping")
    public MappingRsp getIndexMapping(String indexName) {
        return iEngineQueryService.getIndexMapping(indexName);
    }

}
